let dbhelp = require('../../util/Dbhelp');
let { getToken } = require('../../router/Token/index')
const DbuserLogin = async (body) => {
    let data = await dbhelp.sql(`select * from miUser where userName='${body.username}'`);
    if (data.recordset.length) {
        if (data.recordset[0].password == body.password) {
            let token = getToken({
                username: data.recordset[0].userName,
                password: data.recordset[0].password,
                userID: data.recordset[0].userID
            }).token;
            return {
                code: 200,
                msg: "密码正确",
                token,
                userID: data.recordset[0].userID
            }
        } else {
            return {
                code: 404,
                msg: "用户名或密码错误"
            }
        }
    } else {
        return {
            code: 404,
            msg: "用户不存在"
        }
    }
}
// 获取用户信息
const DbuserInfo = async (body) => {
    let data = await dbhelp.sql(`select * from miUser where userID='${body.userID}'`);
    return {
        code: 200,
        data:data.recordset[0]
    }
}
module.exports = {
    DbuserLogin,
    DbuserInfo
}